//
//  CustomAlert.m
//  ChatDemo-UI2.0
//
//  Created by syun on 16/7/14.
//  Copyright © 2016年 syun. All rights reserved.
//

#import "CustomAlert.h"

@implementation CustomAlert
static CustomAlert * alert = nil;
#pragma mark -单例方法
+ (CustomAlert *)ShareCustomAlert
{
    if (alert == nil)
    {
        alert = [[self alloc] init];
    }
    return alert;
}
- (id)init
{
    self = [super init];
    if (self) {
    }
    return self;
}
-(void)showAlertTaskString:(NSString *)str andNum:(int)num
{
    control=[[UIControl alloc]initWithFrame:CGRectMake(0, 0, SCREENWIDTH, SCREENHEIGH)];
    control.backgroundColor=[UIColor clearColor];
    
    UIImageView *img=[[UIImageView alloc]initWithFrame:CGRectMake((SCREENWIDTH-200)/2, (SCREENHEIGH-70)/2, 200,70)];
    img.layer.cornerRadius=6;
    img.backgroundColor=RGBACOLOR(62, 62, 62, 1);
    
    UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(10, 10, 180, 20)];
    label.text=@"已完成";
    label.textColor=[UIColor whiteColor];
    label.font=[UIFont systemFontOfSize:15];
    label.textAlignment=NSTextAlignmentCenter;
    [img addSubview:label];
    
    UILabel *label2=[[UILabel alloc]initWithFrame:CGRectMake(10, label.frame.origin.y+label.frame.size.height+10, 180, 20)];
    label2.text=[NSString stringWithFormat:@"%@任务,增加%d云豆",str,num];
    label2.textAlignment=NSTextAlignmentCenter;
    label2.font=[UIFont systemFontOfSize:14];
    label2.textColor=[UIColor whiteColor];
    [img addSubview:label2];
    
    [control addSubview:img];
    
    UIWindow *window=KeyWindow;
    [window addSubview:control];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        
        
        
        [self cancelAction];
    });
    
//    [self performSelector:@selector(cancelAction) withObject:nil afterDelay:3];
    
   
    
}

- (void)showAlertTaskString:(NSString *)str {
    
    control=[[UIControl alloc]initWithFrame:CGRectMake(0, 0, SCREENWIDTH, SCREENHEIGH)];
    control.backgroundColor=[UIColor clearColor];
    
    UIImageView *img=[[UIImageView alloc]initWithFrame:CGRectMake((SCREENWIDTH-200)/2, (SCREENHEIGH-70)/2, 200,70)];
    img.layer.cornerRadius=6;
    img.backgroundColor=RGBACOLOR(62, 62, 62, 1);
    
    
    
    UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(10, 10, 180, 20)];
    label.text=@"已完成";
    label.textColor=[UIColor whiteColor];
    label.font=[UIFont systemFontOfSize:15];
    label.textAlignment=NSTextAlignmentCenter;
    [img addSubview:label];
    
    UILabel *label2=[[UILabel alloc]initWithFrame:CGRectMake(10, label.frame.origin.y+label.frame.size.height+10, 180, 20)];
    label2.text=str;
    label2.textAlignment=NSTextAlignmentCenter;
    label2.font=[UIFont systemFontOfSize:14];
    label2.textColor=[UIColor whiteColor];
    [img addSubview:label2];
    
    [control addSubview:img];
    
    UIWindow *window=KeyWindow;
    [window addSubview:control];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        
        [self cancelAction];
    });
}
-(void)cancelAction
{
    [control removeFromSuperview];
}
@end
